# -*- coding: utf-8 -*-
# @Time : 2022/1/21 17:38
"""
aim: 创建三个子进程,每个进程执行10次work
面向过程的创建方式
"""

import multiprocessing
import time


def worker(count,delay):
    for i in range(count):
        time.sleep(delay)
        print("[{}]-->pid:{}   pname{}".format(
            i,
            multiprocessing.current_process().pid,# 当前进程id
            multiprocessing.current_process().name, # 当前进程名
        ))


def main():
    for id in range(3):
        process = multiprocessing.Process(target=worker,args=(10,0.5),name="进程{}".format(id))
        process.start()

def main2():
    print("id:[{}]  [name]{}".format(multiprocessing.current_process().pid,
          multiprocessing.current_process().name))

if __name__ == "__main__":
    # main()
    main2() # id:[20784]  [name]MainProcess python 程序执行的就是主进程,所有的子进程需要主进程来创建